package com.zh.api.controller.test;

import com.zh.common.annotation.Log;
import com.zh.common.base.BaseController;
import com.zh.common.domain.RoleDO;
import com.zh.common.service.RoleService;
import com.zh.common.utils.PageUtils;
import com.zh.common.utils.Query;
import com.zh.common.utils.ResultVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;


/**
 * 注释参考东升的注释文件
 */
@Controller
public class DemoController extends BaseController {

    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private RoleService roleService;


    /**
     * value和方法名相同
     * @return
     */
    @Log("获取角色列表")
    @RequestMapping(value = "listRoleByPage", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    @ResponseBody
    public ResultVO listRoleByPage(@RequestBody Map<String,Object> params){

           // 查询列表数据
                Query query = new Query(params);
                List<RoleDO> roleDOList = roleService.list(query);
                int total = roleService.count(query);
                PageUtils pageUtil = new PageUtils(roleDOList, total);
                return ResultVO.success(pageUtil);
    }


    /**
     * value和方法名相同
     * @return
     */
    @Log("添加角色")
    @RequestMapping(value = "saveRole", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    @ResponseBody
    public ResultVO saveRole(@RequestBody RoleDO roleDO){
        // 查询列表数据
        roleService.save(roleDO);
        return ResultVO.success();

    }

    /**
     * value和方法名相同
     * @return
     */
    @Log("修改角色")
    @RequestMapping(value = "editRole", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    @ResponseBody
    public ResultVO editRole(@RequestBody RoleDO roleDO){

            // 查询列表数据
            roleService.update(roleDO);
            return   ResultVO.success();

    }

    /**
     * value和方法名相同
     * @return
     */
    @Log("删除角色")
    @RequestMapping(value = "deleteRole", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    @ResponseBody
    public ResultVO deleteRole(@RequestBody RoleDO roleDO){
            // 查询列表数据
            roleService.remove(roleDO.getRoleId());
            return   ResultVO.success();


    }

}
